<?php

namespace app\bews\controller;
use app\bews\model\Base;
use think\app;
use think\facade\Db;
use think\facade\View;

class Index extends Base
{
    public function index(){
        /*$where = [
            ['status','=',1],
        ];*/
        $group = Db::table("bew_admin_user_group")->where('group_id',$this->aUser['group_id'])->find();

        if($group != null and $group['rights']){
            $smids = json_decode($group['rights']);
        }
        $tree = [];
        if($smids != null){
            $where = [
                ['status','=',1],
                ['smid','in',$smids]
            ];

            $menus = Db::table("bew_admin_sys_menu")->where($where)->order('type,sort DESC')->select()->toArray();

//        print_r($menus);
            foreach ($menus as $menus_v){
                if($menus_v['parent_id'] == 0){
                    $tree[$menus_v['smid']] = $menus_v;
                }else{
                    $tree[$menus_v['parent_id']]['children'][] = $menus_v;
                }
            }
        }
//        print_r($tree);

//        print_r($tree);
        View::assign([
            'menu'=>$tree
        ]);
        return View::fetch();
    }

    public function welcome(){
        return View::fetch();
    }



}